var app = getApp(),
  $ = require("../../utils/httpHelper.js")
var wxParse = require("../../wxParse/wxParse.js")
Page({
  data: {
    userInfo: {},
    size: ['1', '2', '3', '4', '5'],
    page: 1,
    pagesize: 10,
    totalpage: 0,//最大页数,
    tempFilePaths: '',
    filepathArr: [],
    width: 0,
    coll: false,
    cont: '',
    num:0,
    orderno:''
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/mine/reback?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ width: 3 * (res.windowWidth - 40) / 10 })
      }
    })
    
    if (!app.check_empty(options.orderno)) {
      this.setData({
        orderno: options.orderno
      })
    }


  },
  oncont(e) {
    let value = e.detail.value
    this.setData({
      cont: value,
      num:value.length
    })
  },
  commentOrder(){
    if (!app.check_empty(this.data.cont)){
      let par = {
        rd_session: wx.getStorageSync('rd_session'),
        content: this.data.cont,
      }
      $.httpPost("add_suggest", par, (data, err) => {
        if(data.result == 'success'){
          wx.switchTab({
            url: '/pages/mine/mine',
          })
        }
      })
    }else{
      wx.showToast({
        title: '评论不能是空',
      })
    }
    
  },
  chooseimage: function (e) {
    var that = this;
    console.log(that.data.filepathArr.length)
    if (that.data.filepathArr.length > 5) {
      wx.showToast({
        title: '不能超过六张',
      })
      return;
    }
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#9C0097",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImage('album')
          } else if (res.tapIndex == 1) {
            that.chooseWxImage('camera')
          }
        }
      }
    })

  },

  chooseWxImage: function (type) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        //去上传
        var tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: 'https://tuomao.zzxkeji.cn/Api//upload_image', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'user': 'test',
            'mchid': 'd072f71878ca8a3288b05bb50c0ecc65',
            'rd_session': app.globalData.userInfo.rd_session,
          },
          success: function (res) {
            var data = res.data
            //do something
            data = JSON.parse(data)
            if(data.result == 'success'){
              let arr = that.data.filepathArr
              arr.push(data.data.data)
              that.setData({
                tempFilePaths: data.data.data,
                coll: true,
                filepathArr: arr
              })
            }else{
              wx.showToast({
                title: '上传失败~',
              })
            }
            
          }
        })


      }
    })
  }

});